<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <style>
        .demo01 {
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- 阻止默认行为 -->
        <a href="https://www.baidu.com" @click.prevent="showInfo">点击跳转</a>

        <!-- 阻止事件的冒泡 -->
        <div class="demo01" @click="show">
            <!-- <button @click.stop="show">我是按钮</button> -->
            <!-- 可以连续书写 -->
            <a href="https://www.baidu.com" @click.prevent.stop="show">我是按钮</a>
        </div>

        <!-- 事件只触发一次 -->
        <button @click.once="show">我是按钮</button>

        <!-- self只有当前点击的事件的event是自己才会触发 -->
        <div class="demo01" @click.self="show">
            <button @click="show">我是按钮</button>
        </div>

    </div>

</body>

</html>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                name: 'zs'
            }
        },
        methods: {
            showInfo() {
                console.log('你好');
            },
            show() {
                alert('消息')
            }
        }
    })

</script>